interface ResultInterface {
  os: 'light' | 'dark'
}

/**
 * 获取当前系统的主题
 * @param {(x: ResultInterface) => void} callback 系统主题变化触发的回调
 */
export const useTheme = (
  callback?: (x: ResultInterface) => void,
): ResultInterface => {
  const match = matchMedia('(prefers-color-scheme: dark)')
  match.onchange = (event) => {
    callback && callback(event.matches ? { os: 'dark' } : { os: 'light' })
  }
  if (match.matches) {
    return { os: 'dark' }
  }
  return { os: 'light' }
}
